﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class glDRIVE
{
    /*
    函数 gl.aitken
    Aitken逐步插值
    参数 x: x[n]存放n个给定的有序结点值。
    参数 y: y[n]存放n个给定结点上的函数值。
    参数 n: n给定结点的个数。
    参数 eps: eps插值的精度要求。
    参数 t: t指定插值点值。
    返回值 函数返回指定插值点t处的函数近似值。
    */
    /*
    public static string drive_aitken()
    {
        double[] x = new double[11] { -1.0, -0.8, -0.65, -0.4, -0.3, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 };
        double[] y = new double[11] { 0.0384615, 0.0588236, 0.0864865, 0.2, 0.307692, 1.0, 0.5, 0.2, 0.1, 0.0588236, 0.0384615 };
        double[] t = new double[2];
        double[] z = new double[2];
        double eps;
        eps = 1.0e-6;

        t[0] = -0.75;
        z[0] = gl.aitken(x, y, 11, eps, t[0]);
        t[1] = 0.05;
        z[1] = gl.aitken(x, y, 11, eps, t[1]);
        return gl.html_table("", new double[2, 2] { { t[0], z[0] }, { t[1], z[1] } });
    }
    */
    public static string drive_aitken(int w, int h)
    {
        double[] x = new double[11] { -1.0, -0.8, -0.65, -0.4, -0.3, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 };
        double[] y = new double[11] { 0.0384615, 0.0588236, 0.0864865, 0.2, 0.307692, 1.0, 0.5, 0.2, 0.1, 0.0588236, 0.0384615 };
        double[] t = new double[2];
        double[] z = new double[2];
        double eps = 1.0E-6;

        int pk = 10;
        double[] px = new double[(x.Length - 1) * pk + 1];
        double[] py = new double[(x.Length - 1) * pk + 1];
        for (int i = 0; i < x.Length - 1; i++)
        {
            for (int j = 0; j <= pk; j++)
            {
                px[i * pk + j] = x[i] + (x[i + 1] - x[i]) * ((double)j / (double)pk);
                py[i * pk + j] = gl.aitken(x, y, x.Length, eps, px[i * pk + j]);
            }
        }

        return html_image(w, h, px, py,
            new double[] { -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 },
            new double[] { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 },
            x,
            y
            );
    }
}